package algorithm;

import java.util.List;

import algorithm.distance.DistanceFunction;

import de.gugubarra.core.nop.Nop;

import main.data.Centroid;
import main.data.Membership;
import main.data.MinDistance;
import main.data.OPT;
import main.data.dataManager.DataManager;
import main.data.dataManager.DataManagerSimpleImpl;

public class DoubleAlgorithm {

	private DataManagerSimpleImpl dataManager = new DataManagerSimpleImpl();
	private List<Centroid> centroidList = dataManager.getCentroidList();
	private List<Nop> nopList = dataManager.getNopList();
	private int numberOfUser = dataManager.getNumberOfUser();
	private int numberOfCluster = dataManager.getNumberOfCluster();
	private List<Membership> membershipMatrix;
	
	private OPT opt;

	public void pause() {
	}

	public void stop() {
	}

	public void resume() {
	}

	public void reset() {
	}

	public void addNewPoint() {
		for (int i = 0; i < numberOfUser; i++) {
			OPT opt = getOPT(centroidList ,membershipMatrix);
			MinDistance minDistance = getMinDistance(nopList.get(i));
			if (minDistance.getMinDistace() < opt.getOptimalDiameter()) {
				// add new
				addMembershipColumn(nopList.get(i));

			} else {
				// merge and add
				addMembershipColumn(nopList.get(i));
				addMembershipRow(nopList.get(i));

				mergeCluster(centroidList);
				updateCentroids();
			}
		}
	}
	
	public MinDistance getMinDistance(Nop x) {
		
		return null;
	}

	public OPT getOPT(List<Centroid> centroidList, List<Membership> membershipMatrix) {
		
		return this.opt;
	}

	public void addMembershipColumn(Nop nop) {

	}

	public void addMembershipRow(Nop nop) {
	}

	public void updateCentroids() {

	}

	public void mergeCluster(List<Centroid> centroidList) {
		/*//2 indices for the closest Centroids
		int indexOfCentroid_1, indexOfCentroid_2;
		double distance;
		for (int i=0;i<centroidList.size();i++){
			for(int j=i+1;j<centroidList.size();j++){
				//return the minimum of distance between two centroids
				//and the indices of the two centroids
			}
		}*/
		int index_1 = (int)(Math.random()*centroidList.size());
		int index_2 = (int)(Math.random()*centroidList.size());
		while(index_1 == index_2){
			index_2 = (int)(Math.random()*centroidList.size());
		}
		
	}
}
